<?php
declare (strict_types = 1);
namespace app\index\model\order;

use think\Model;

/**
 * @mixin \think\Model
 */
class PileOrderSon extends Model
{
    protected $pk = "id";

    /**
     * 获取订单最后一条记录
     * @param $orderId
     * @return array|null|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getLastOrderSonInfo($orderId){
        $result = $this->where('order_id',$orderId)->order('id','desc')->find();
        if($result) $result = $result->toArray();
        return $result;
    }

    /**
     * 获取订单最后指定条数记录
     * @param $orderId
     * @param int $page
     * @param int $limit
     * @return array|null|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getLastOrderSonList($orderId,$page = 1,$limit = 10){
        return $this->where('order_id',$orderId)->order('id','desc')
            ->page($page,$limit)->select()->toArray();
    }

}
